li r1, 10
li r13, 50
li r3, 100

addi r6, r0, 0  // outer loop counter  r6=j
addi r7, r0, 0  // inner loop counter  r7=i 

addi r12, r14, -1     // r12 has N-1

OUTERLOOP1:
sub r8, r12, r6       // (N-1) -j >0
bez r8, ENDOUTERLOOP1 
blz r8, ENDOUTERLOOP1 

addi r11, r0, 0     // y(j)  = 0
addi r7, r0, 0      // inner loop counter
add r2, r6, r13      // index of array x starts at j and decreases
addi r1, r0, 0       // initialize i as 0 each time for H(i)
li r1, 10
INNERLOOP1:
sub r8, r6, r7        // while j-i >=0 .. 
blz r8, ENDINNERLOOP1


load r4, 0(r1)
load r5, 0(r2)
mul r9, r4, r5    // y(j) = y(j) + h(i)* x(j-i)
add r11, r11, r9


addi r1, r1, 1    // incrementing the H array address
addi r2, r2, -1   // decrementing the x array address


addi r7, r7, 1

bez r0, INNERLOOP1
ENDINNERLOOP1:
store r11, 0(r3)  
addi r3, r3, 1


addi r6, r6, 1
bez r0, OUTERLOOP1
ENDOUTERLOOP1:

//********j= N-1 to M-1**********************

addi r1, r0, 0
li   r1, 10
addi r12, r15, -1     // r12 has M-1

OUTERLOOP2:


sub r8, r12, r6
blz r8, ENDOUTERLOOP2 
bez r8, ENDOUTERLOOP2 

addi r11, r0, 0     // y(j)  = 0
addi r7, r0, 0      // inner loop counter
add r2, r6, r13      // index of array x starts at j and decreases
addi r1, r0, 0       // initialize i as 0 each time for H(i)
li r1, 10
INNERLOOP2:
sub r8, r14, r7       //  N > i
blz r8, ENDINNERLOOP2 
bez r8, ENDINNERLOOP2 

load r4, 0(r1)
load r5, 0(r2)
mul r9, r4, r5    // y(j) = y(j) + h(i)* x(j-i)
add r11, r11, r9


addi r1, r1, 1  // incrementing the H array address
addi r2, r2, -1  // decrementing the x array address


addi r7, r7, 1

bez r0, INNERLOOP2
ENDINNERLOOP2:
store r11, 0(r3)
addi r3, r3, 1


addi r6, r6, 1
bez r0, OUTERLOOP2
ENDOUTERLOOP2:

//****** j= M-1 to M+N-1***************

add  r12, r14, r15
addi r12, r12, -1     // r12 has M+N-1

OUTERLOOP:

sub r8, r12, r6   // (N+M-1) - j  > 0
blz r8, ENDOUTERLOOP 
bez r8, ENDOUTERLOOP 
addi r11, r0, 0     // y(j)  = 0
sub  r7, r6, r15    
addi r7, r7, 1      // r7 contains j-M+1
addi r1, r0, 0
li   r1, 10
add  r1, r7, r1      // index of  H = 10 + (j-M+1)

addi  r2, r15, -1     // index of X = j-i starts at M-1 each time
add  r2, r13, r2       


INNERLOOP:
sub r8, r14, r7       // 
blz r8, ENDINNERLOOP 
bez r8, ENDINNERLOOP 

load r4, 0(r1)
load r5, 0(r2)
mul r9, r4, r5    // y(j) = y(j) + h(i)* x(j-i)
add r11, r11, r9


addi r1, r1, 1  // incrementing the H array address
addi r2, r2, -1  // decrementing the x array address


addi r7, r7, 1
bez r0, INNERLOOP
ENDINNERLOOP:

store r11, 0(r3)
addi r3, r3, 1


addi r6, r6, 1
bez r0, OUTERLOOP

ENDOUTERLOOP: